<template>
    <div style="height: 100%" class="warp-2 body-content">
        <navbar :title="$t('mall_3')"></navbar>
        <div class="content-noBottom">
            <van-pull-refresh v-model="isRefresh" @refresh="onPulldownTop" loading-text="loading" pulling-text="" loosing-text="" style="height: 100%;">
                <van-list
                v-model="isLoading"
                :finished="finished"
                :finished-text="(finished&&total>0) ? $t('no_more') : ''"
                loding-text="loading"
                @load="getMallList"
                >
                    <mall :mall-list="list" :is-no-more="finished" :is-height="true"></mall>
                </van-list>
            </van-pull-refresh>
        </div>
        <common-loading :isLoading="isLoading"></common-loading>
    </div>
</template>

<script>
import Mall from './Mall';
export default {
    name: 'ConvertibleMallList',
    components: {
        Mall
    },
    data() {
        return {
            total: 0,
            pageNo: 0,
            list: [],
            isLoading: false,
            finished: false,
            isRefresh: false
        };
    },
    methods: {
        getMallList(option) {
            this.$axios.post(`/app/api/trainee/im/product/list?pageNo=${this.pageNo}`, {imcId: 0, type: 3}).then(res => {
                if (res.data.results && res.data.results.length !== 0) {
                    if (option && option === 'refresh') {
                        this.list = res.data.results;
                    } else {
                        this.list = [...this.list, ...res.data.results];
                    }
                }
                this.total = res.data.totalRecord;
                this.isLoading = false;
                this.pageNo++;
                if (this.list.length >= this.total) {
                    this.finished = true;
                }
            });
        },
        /*下拉刷新*/
        onPulldownTop() {
            this.isRefresh = true;
            setTimeout(() => {
                this.finished = false;
                this.pageNo = 1;
                this.getMallList('refresh');
                this.isRefresh = false;
            }, 900);
        }
    },
    created() {
        this.isLoading = true;
        this.onPulldownTop();
    }
};
</script>

<style scoped>

</style>
